From Rick Richardson:
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 25 Jan 2003 18:55:28 +0000 (18:55 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 25 Jan 2003 18:55:28 +0000 (18:55 +0000)
This patch adds a proper usage message (although the wording
may need to be fixed), more standards-like option parsing,
and the ability to specify the input and output files as positional
parameters rather than options.

gpsbabel/main.c
gpsbabel/vecs.c

index 6e5cda912f6ec230f5f493f175b8c3ee1d796557..d44b09dd4b15295611ffc04740ded6c80f405b53 100644 (file)
@@ -26,9 +26,33 @@ global_options global_opts;
 void
 usage(const char *pname)
 {
-       printf("GPSBabel Version %s.  http://gpsbabel.sourceforge.net\n",VERSION );
-       printf("Usage: %s [-s] [-t|-w|-r] -i <INPUT_FILE_TYPE> -f <INPUT_FILE> -o <OUT FTYPE> -F <OUTPUT_FILE>\n", pname);
-       printf("Supported file types:\n");
+       printf("GPSBabel Version %s.  http://gpsbabel.sourceforge.net\n\n",
+                       VERSION );
+       printf(
+"Usage:\n"
+"      %s [options] -i INTYPE -f INFILE -o OUTTYPE -F OUTFILE\n"
+"      %s [options] -i INTYPE -o OUTTYPE INFILE [OUTFILE]\n"
+"\n"
+"      Converts GPS route and waypoint data from one format type to another.\n"
+"      The input type and filename are specified with the -i INTYPE\n"
+"      and -f INFILE options. The output type and filename are specified\n"
+"      with the -o OUTTYPE and -F OUTFILE options.\n"
+"\n"
+"      In the second form of the command, INFILE and OUTFILE are the\n"
+"      first and second positional (non-option) arguments.\n"
+"\n"
+"Options:\n"
+"      -s              Synthesize shortnames\n"
+"      -r              Process route information\n"
+"      -t              Process track information\n"
+"      -w              Process waypoint information [default]\n"
+"      -D level        Set debug level [%d]\n"
+"\n"
+"File Types (-i and -o options):\n"
+       , pname
+       , global_opts.debug_level
+       );
+
        disp_vecs();
 }
 
@@ -58,7 +82,10 @@ main(int argc, char *argv[])
                char *optarg;
 
                if (argv[argn][0] != '-') {
-                       fatal ("argument '%s' not understood\n",argv[argn]);
+                       break;
+               }
+               if (argv[argn][1] == '-') {
+                       break;
                }
 
                if (argv[argn][1] == '?' || argv[argn][1] == 'h') {
@@ -67,20 +94,22 @@ main(int argc, char *argv[])
                }
 
                c = argv[argn][1];
-               optarg = argv[argn+1];
 
                switch (c) {
                        case 'i': 
+                               optarg = argv[argn][2]
+                                       ? argv[argn]+2 : argv[++argn];
                                ivecs = find_vec(optarg, &ivec_opts);
-                               argn++;
                                break;
                        case 'o':
+                               optarg = argv[argn][2]
+                                       ? argv[argn]+2 : argv[++argn];
                                ovecs = find_vec(optarg, &ovec_opts);
-                               argn++;
                                break;
                        case 'f':
+                               optarg = argv[argn][2]
+                                       ? argv[argn]+2 : argv[++argn];
                                fname = optarg;
-                               argn++;
                                if (ivecs == NULL) {
                                        fatal ("No valid input type specified\n");
                                }
@@ -89,8 +118,9 @@ main(int argc, char *argv[])
                                ivecs->rd_deinit();
                                break;
                        case 'F':
+                               optarg = argv[argn][2]
+                                       ? argv[argn]+2 : argv[++argn];
                                ofname = optarg;
-                               argn++;
                                if (ovecs) {
                                        ovecs->wr_init(ofname, ovec_opts);
                                        ovecs->write();
@@ -110,8 +140,9 @@ main(int argc, char *argv[])
                                global_opts.objective = rtedata;
                                break;
                        case 'D':
+                               optarg = argv[argn][2]
+                                       ? argv[argn]+2 : argv[++argn];
                                global_opts.debug_level = atoi(optarg);
-                               argn++;
                                break;
                        case '^':
                                disp_formats();
@@ -123,6 +154,26 @@ main(int argc, char *argv[])
                }
        }
 
+       /*
+        * Allow input and output files to be specified positionally
+        * as well.  This is the typical command line format.
+        */
+       argc -= argn;
+       argv += argn;
+       if (argc > 2) {
+               fatal ("Extra arguments on command line\n");
+       }
+       else if (argc) {
+               ivecs->rd_init(argv[0], ivec_opts);
+               ivecs->read();
+               ivecs->rd_deinit();
+               if (argc == 2 && ovecs) {
+                       ovecs->wr_init(argv[1], ovec_opts);
+                       ovecs->write();
+                       ovecs->wr_deinit();
+               }
+       }
+
        if (ovecs == NULL)
                waypt_disp_all(waypt_disp);
 
index f273878f5b5807ba80b155d59336fd5ea55f66dc..f7dfb6bd6922e4d35862bc5a8d603ddef17e4250 100644 (file)
@@ -296,7 +296,7 @@ disp_vecs(void)
 {
        vecs_t *vec;
        for (vec = vec_list; vec->vec; vec++) {
-               printf("%-20.20s  %-50.50s\n",
+               printf("        %-20.20s  %-50.50s\n",
                        vec->name, vec->desc);
        }
 }